/**
 * Copyright &copy; 2017-2020 <a href="http://www.fosung.com/">FosungFrame</a> All rights reserved.
 */
package com.fosung.frame.modules.approve.web;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fosung.frame.common.utils.StringUtils;
import com.fosung.frame.common.web.BaseController;
import com.fosung.frame.modules.approve.entity.HomeApprove;
import com.fosung.frame.modules.approve.service.HomeApproveService;
import com.fosung.frame.modules.sys.entity.Dict;
import com.fosung.frame.modules.sys.utils.DictUtils;
import com.fosung.frame.modules.sys.utils.UserUtils;

/**
 * 首页Controller
 * @author ygl
 * @version 2017-08-30
 */
@Controller
@RequestMapping(value = "${adminPath}/approve/homeApprove")
public class HomeApproveController extends BaseController {

	@Autowired
	private HomeApproveService homeApproveService;
	
	@ModelAttribute
	public HomeApprove get(@RequestParam(required=false) String id) {
		HomeApprove entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = homeApproveService.get(id);
		}
		if (entity == null){
			entity = new HomeApprove();
		}
		return entity;
	}
	
	@RequiresPermissions("approve:homeApprove:view")
	@RequestMapping(value = {"list", ""})
	public String list(HomeApprove homeApprove, HttpServletRequest request, HttpServletResponse response, Model model) {
		List<Dict> partyTypeList = DictUtils.getPartyType();
		List<Dict> findAssessmentTimeList = DictUtils.findAssessmentTimeList();
		String year = findAssessmentTimeList.size()>0?findAssessmentTimeList.get(0).getLabel():new SimpleDateFormat("yyyy").format(new Date());
		String orgId = UserUtils.getUser().getOffice().getId();
		model.addAttribute("partyTypeList", partyTypeList);
		model.addAttribute("orgId", orgId);
		model.addAttribute("year", year);
		return "modules/approve/homeApproveList";
	}

	@RequiresPermissions("approve:homeApprove:view")
	@RequestMapping(value = "form")
	public String form(HomeApprove homeApprove, Model model) {
		model.addAttribute("homeApprove", homeApprove);
		return "modules/approve/homeApproveForm";
	}

	/**
	 * 查询组织生活申请待审核数据
	 * @param homeApprove
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "findOrganizeLifeJhList")
	@ResponseBody
	public List<HomeApprove> findOrganizeLifeJhList(HomeApprove homeApprove, HttpServletRequest request, HttpServletResponse response, Model model) {
		List<HomeApprove> list = homeApproveService.findOrganizeLifeJhList(homeApprove); 
		return list;
	}
	
	/**
	 * 首页功能 查询积分申请数据
	 * @param homeApprove
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "findOrganizeLifeJfList")
	@ResponseBody
	public List<HomeApprove> findOrganizeLifeJfList(HomeApprove homeApprove, HttpServletRequest request, HttpServletResponse response, Model model) {
		List<HomeApprove> list = homeApproveService.findOrganizeLifeJfList(homeApprove); 
		return list;
	}
	

}